|
Working with a list of variables
The notion of variables was minutely explained in the corresponding chapter. Let us briefly call to mind the main points. A user can specify one or several variables in a report. A value or an expression, which will be automatically calculated when referring to a variable, can be assigned to every variable. Variables can be visually inserted into a report via the “Data tree” window. It is convenient to use variables for aliasing of compound expressions, which are often used in a report. It is necessary to use the “frxVariables” unit when working with variables. Variables are represented by the “TfrxVariable” class. TfrxVariable = class (TCollectionItem) published Name of a variable property Value: Variant; Value of a variable end; The list of variables is represented by the “TfrxVariables” class. It contains all methods necessary for working with the list. TfrxVariables = class (TCollection) public Adds a variable to the end of the list function Insert(Index: Integer): TfrxVariable; Adds a variable to the given position of the list function IndexOf( const Name: String ): Integer; Returns the index of a variable with the given name procedure AddVariable( const ACategory, AName: String ; const AValue: Variant); Adds a variable to the specified category procedure DeleteCategory( const Name: String ); Deletes a category and all its variables procedure DeleteVariable( const Name: String ); Deletes a variable procedure GetCategoriesList(List: TStrings; ClearList: Boolean = True); Returns the list of categories procedure GetVariablesList( const Category: String; List: TStrings); Returns the list of variables in the specified category property Items[Index: Integer]: TfrxVariable readonly; The list of variables property Variables[Index: String]: Variant; default; Values of variables end; If the list of variables is long, it is convenient to group it by categories. For example, when having the following list of variables: Customer name Account number in total total vat one can represent it in the following way: Properties Customer name Account number Totals In total total vat There are the following limitations: - at least one category must be created - categories form the first level of the data tree, variables form the second one - categories cannot be nested - variables’ names must be unique within a whole list, not within a category |